const { series, parallel, src, dest } = require('gulp')

const htmlmin = require('gulp-htmlmin');
const uglify = require('gulp-uglify');
const del = require('del')
// 删除resources下的index.html,index.js,base
function clean() {
  return del(['resources/index.html', 'resources/index.js', 'resources/base/**'])
}
// 压缩html
function hlmin() {
  return src('proxy-app/index.html')
    .pipe(htmlmin({
      removeComments: true, //清除HTML注释
      collapseWhitespace: true, //压缩HTML
      collapseBooleanAttributes: true, //省略布尔属性的值 <input checked="true"/> ==> <input />
      removeEmptyAttributes: true, //删除所有空格作属性值 <input id="" /> ==> <input />
      removeScriptTypeAttributes: true, //删除<script>的type="text/javascript"
      removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type="text/css"
      minifyJS: true, //压缩页面JS
      minifyCSS: true //压缩页面CSS
    }))
    .pipe(dest('resources'))
}
// 压缩js
function jsmin() {
  return src('proxy-app/index.js')
    .pipe(uglify())
    .pipe(dest('resources'))
}
// 拷贝静态资源
function copyAssets() {
  return src('proxy-app/base/**')
    .pipe(dest('resources/base'))
}
exports.default = series(clean, hlmin, jsmin, copyAssets)


